from flask import g, redirect, url_for
from functools import wraps


def login_required(f):
    # @wraps这个装饰器一定要记住
    @wraps(f)
    def wrapper(*args, **kwargs):
        if hasattr(g, 'user'):
            res = f(*args, **kwargs)
            return res
        else:
            return redirect(url_for("user.login"))
    return wrapper
